#ifndef RASTERIZER_H_
#define RASTERIZER_H_


#include <IRasterizer.h>

#define CLIP_BUFFER_SIZE 2*6+1

#define DEPTH_IMAGE_FORMAT ushort
#define COLOR_IMAGE_FORMAT uchar
#define COLOR_BUFFER_CHANNELS 3
#define MAX_DEPTH_VALUE 65535
#define MAX_COLOR_VALUE 255




ATTRIBUTE_ALIGNED16(class) AbstractRasterizer : public IRasterizer
{
public:
	AbstractRasterizer();
	virtual ~AbstractRasterizer();

	virtual Mesh* addMesh(const std::string& name, objLoader& obj,  const Vec3& loc=Vec3(0,0,0), const Vec3& rot = Vec3(0,0,0), const Vec3& sca=Vec3(1,1,1));
	virtual void beginMesh(const std::string& name);
	virtual Mesh* endMesh();
	virtual void addVertex(const Vec4& p, const Color4& c, const Vec4& n, const Vec2& t);
	virtual void addVertex(const Vertex& vertex);
	virtual void addIndex(size_t idx);
	virtual Texture* loadTexture(const std::string& path);

	virtual double render();//returns the time

	virtual RenderTarget* createRenderTarget(int width, int height);
	virtual void setRenderTarget(RenderTarget* rt) { mShaderGlobals.renderTarget = rt;}

	virtual void setVertexShader(VERTEXSHADER vs ) { mVertexShader = vs; }
	virtual void setFragmentShader(FRAGMENTSHADER fs) { mFragmentShader = fs; }
	virtual void setTransform(IRasterizer::TRANSFORM t, const Mat4x4& m);

protected:
	virtual void prepareForRender() = 0;
	virtual void renderMesh(const Mesh& mesh) = 0;

	std::vector<Mesh*>			mMeshes;
	Mesh*						mCurrentMesh;
	Face						mCurrentFace;
	int							mCurrentFaceIdx;
	
	ShaderGlobals				mShaderGlobals;

	VertexShaderParameters		mVShaderParams;
	VERTEXSHADER				mVertexShader;
	FragmentShaderParameters	mFShaderParams;
	FRAGMENTSHADER				mFragmentShader;
};

#endif //RASTERIZER_H_